package com.mcxx.modules.nopage.service.read;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mcxx.modules.miniSalvation.order.entity.OrderEntity;
import com.mcxx.modules.nopage.dao.read.DocNoPagXTYHLowDataReadDao;
import com.mcxx.modules.nopage.dto.XTYHDBBSalvationEFileDTO;
import com.yinhai.ta404.core.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DocNoPageLowDataReadService extends BaseService {

    @Autowired
    private DocNoPagXTYHLowDataReadDao docNoPagXTYHDataReadDao;


    public XTYHDBBSalvationEFileDTO getEFileXTYHLOWInfo(String orderId) {
        XTYHDBBSalvationEFileDTO miniSalvationEFileYHDTO =  docNoPagXTYHDataReadDao.getEFileHNDBDTOInfo(orderId);


        XTYHDBBSalvationEFileDTO financial = docNoPagXTYHDataReadDao.selectFinancialByOrderId(orderId);

        if(miniSalvationEFileYHDTO!=null) {

            if (financial != null) {
                miniSalvationEFileYHDTO.setPO_yearwageIncome(financial.getPO_yearwageIncome());
                miniSalvationEFileYHDTO.setPO_wageIncome(financial.getPO_wageIncome());
                miniSalvationEFileYHDTO.setPO_wageComputer(financial.getPO_wageComputer());
                miniSalvationEFileYHDTO.setPO_yearbusinessIncome(financial.getPO_yearbusinessIncome());
                miniSalvationEFileYHDTO.setPO_businessIncome(financial.getPO_businessIncome());
                miniSalvationEFileYHDTO.setPO_businessComputer(financial.getPO_businessComputer());
                miniSalvationEFileYHDTO.setPO_yearpropertyIncome(financial.getPO_yearpropertyIncome());
                miniSalvationEFileYHDTO.setPO_propertyIncome(financial.getPO_propertyIncome());
                miniSalvationEFileYHDTO.setPO_propertyComputer(financial.getPO_propertyComputer());
                miniSalvationEFileYHDTO.setPO_transformIncome(financial.getPO_transformIncome());
                miniSalvationEFileYHDTO.setPO_yeartransformIncome(financial.getPO_yeartransformIncome());
                miniSalvationEFileYHDTO.setPO_transformComputer(financial.getPO_transformComputer());
                miniSalvationEFileYHDTO.setPO_yearotherIncome(financial.getPO_yearotherIncome());
                miniSalvationEFileYHDTO.setPO_otherIncome(financial.getPO_otherIncome());
                miniSalvationEFileYHDTO.setPO_otherInComputer(financial.getPO_otherInComputer());
                miniSalvationEFileYHDTO.setPO_incomeCount(financial.getPO_incomeCount());
                miniSalvationEFileYHDTO.setPO_yearillnessOutcome(financial.getPO_yearillnessOutcome());
                miniSalvationEFileYHDTO.setPO_illnessOutcome(financial.getPO_illnessOutcome());
                miniSalvationEFileYHDTO.setPO_illnessComputer(financial.getPO_illnessComputer());
                miniSalvationEFileYHDTO.setPO_educationOutcome(financial.getPO_educationOutcome());
                miniSalvationEFileYHDTO.setPO_educationComputer(financial.getPO_educationComputer());
                miniSalvationEFileYHDTO.setPO_yearotherOutcome(financial.getPO_yearotherOutcome());
                miniSalvationEFileYHDTO.setPO_otherOutcome(financial.getPO_otherOutcome());
                miniSalvationEFileYHDTO.setPO_otherOutComputer(financial.getPO_otherOutComputer());
                miniSalvationEFileYHDTO.setPO_income(financial.getPO_income());
                miniSalvationEFileYHDTO.setPO_carForInfo(financial.getPO_carForInfo());
            }

            String s = docNoPagXTYHDataReadDao.selectIncomeCalculate(orderId);
            if (StringUtils.isNotEmpty(s)) {
                JSONObject tempjsonObject = JSONObject.parseObject(s);
                JSONObject jsonObject = tempjsonObject.getJSONObject("totalSalay");
                if (jsonObject != null) {
                    miniSalvationEFileYHDTO.setPO_otherban1Count(jsonObject.getString("otherban1Total"));
                    miniSalvationEFileYHDTO.setPO_otherban2Count(jsonObject.getString("otherban2Total"));
                    miniSalvationEFileYHDTO.setPO_other4Count(jsonObject.getString("other4Total"));
                }
            }
        }

        return miniSalvationEFileYHDTO;
    }


    public OrderEntity getOrderById(String orderId){
        return docNoPagXTYHDataReadDao.getOrderById(orderId);
    }


    public List<XTYHDBBSalvationEFileDTO.FamilyMemberInfo> getFamilyMemberInfo(String orderId, String tempType) {
        return docNoPagXTYHDataReadDao.getFamilyMemberInfo(orderId, tempType);
    }


    public List<XTYHDBBSalvationEFileDTO.SupportPeopleInfo> getSupportPeopleInfo(String orderId) {
        return docNoPagXTYHDataReadDao.getSupportPeopleInfo(orderId);
    }


    public List<XTYHDBBSalvationEFileDTO.SurveyFamilyMemberInfo> getSurveyFamilyMemberInfo(String orderId, String tempType) {
        return docNoPagXTYHDataReadDao.getSurveyFamilyMemberInfo(orderId, tempType);
    }


    public List<XTYHDBBSalvationEFileDTO.SurveySupportPeopleInfo> getSurveySupportPeopleInfo(String orderId) {
        return docNoPagXTYHDataReadDao.getSurveySupportPeopleInfo(orderId);
    }


    public List<XTYHDBBSalvationEFileDTO.ApplyFamilyBuildingsInfo> getApplyFamilyBuildingsInfo(String orderId) {
        return docNoPagXTYHDataReadDao.getApplyFamilyBuildingsInfo(orderId);
    }


    public String getIncomeCalculate(String orderid){
        return docNoPagXTYHDataReadDao.selectIncomeCalculate(orderid);
    }

}
